package model;

import java.io.Serializable;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;

@PersistenceCapable
public class User implements Serializable {

	private static final long serialVersionUID = -5072613744405857491L;

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key sifra;

	private String username;
	private String password;
	private boolean loggedIn;
	private boolean admin;

	public User() {
	}

	public User(String username, String password) {
		super();
		this.username = username;
		this.password = password;
		this.loggedIn = false;
	}

	public User(String username, String password, boolean admin) {
		super();
		this.username = username;
		this.password = password;
		this.loggedIn = false;
		this.admin = admin;
	}

	public User(Key sifra, String username, String password) {
		super();
		this.sifra = sifra;
		this.username = username;
		this.password = password;
		this.loggedIn = false;
	}

	public Key getSifra() {
		return sifra;
	}

	public void setSifra(Key sifra) {
		this.sifra = sifra;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean isLoggedIn() {
		return loggedIn;
	}

	public void setLoggedIn(boolean loggedIn) {
		this.loggedIn = loggedIn;
	}

	public boolean isAdmin() {
		return admin;
	}

	public void setAdmin(boolean admin) {
		this.admin = admin;
	}
	
	@Override
	public boolean equals(Object obj) {
		// ako su username i password isti i korisnici su isti
		User user = null;
		try {
			user = (User) obj;
		} catch (Exception e) {
			return false;
		}

		if (!this.username.equals(user.username))
			return false;

		if (!this.password.equals(user.password))
			return false;
		return true;
	}

	public String toString() {
		return "Korisnik: key: " + sifra + ", username = " + username
				+ ", password = " + password + ", logged = " + loggedIn;
	}
}
